package com.chuangyang.fixboxmaster.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.chuangyang.fixboxmaster.R;
import com.chuangyang.fixboxmaster.bean.PayType;

import java.util.ArrayList;

/**
 * Created by Administrator on 2015/4/30.
 */
public class PayTypeAdapter extends BaseAdapter {

    private ArrayList<PayType> mTypes;
    private Context mContext;
    private LayoutInflater inflater; // 视图容器

    public PayTypeAdapter(Context context, ArrayList<PayType> types){
        inflater = LayoutInflater.from(context);
        this.mContext = context;
        this.mTypes = types;
    }

    @Override
    public int getCount() {
        return mTypes.size();
    }

    @Override
    public PayType getItem(int position) {
        return mTypes.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null)
        {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.pay_type_list_item,parent, false);
            holder.selectIV = (ImageView)convertView.findViewById(R.id.pay_type_selected);
            holder.typeIcon = (ImageView)convertView.findViewById(R.id.pay_type_icon);
            holder.name = (TextView)convertView.findViewById(R.id.pay_type_name);
            holder.desc = (TextView)convertView.findViewById(R.id.pay_type_desc);
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder)convertView.getTag();
        }

        PayType type = getItem(position);

        if (type != null)
        {
            if (type.type == PayType.PAY_TYPE_ZHIFUBAO)
            {
                holder.typeIcon.setImageResource(R.drawable.ic_pay_type_zhifubao);
                holder.name.setText("支付宝支付");
                holder.desc.setText("推荐支付宝客户端用户使用");
            }
            else  if (type.type == PayType.PAY_TYPE_WEIXIN)
            {
                holder.typeIcon.setImageResource(R.drawable.ic_pay_type_weixin);
                holder.name.setText("微信支付");
                holder.desc.setText("推荐已安装微信的用户使用");
            }
            else  if (type.type == PayType.PAY_TYPE_YINLIAN)
            {
                holder.typeIcon.setImageResource(R.drawable.ic_pay_type_yinlian);
                holder.name.setText("银联支付");
                holder.desc.setText("支持信用卡储蓄卡,无需开通网银");
            }
            else  if (type.type == PayType.PAY_TYPE_ZHIFUBAO_OTHER)
            {
                holder.typeIcon.setImageResource(R.drawable.ic_pay_type_zhifubao_other);
                holder.name.setText("支付宝代付");
                holder.desc.setText("请身边的人使用支付宝帮您代付");
            }
            else  if (type.type == PayType.PAY_TYPE_WEIXIN_OTHER)
            {
                holder.typeIcon.setImageResource(R.drawable.ic_pay_type_weixin_other);
                holder.name.setText("微信代付");
                holder.desc.setText("请身边的人使用微信帮您代付");
            }

            if (type.isCheck)
            {
                holder.selectIV.setVisibility(View.VISIBLE);
            }
            else
            {
                holder.selectIV.setVisibility(View.INVISIBLE);
            }
        }

        return convertView;
    }

    class ViewHolder{

        private ImageView selectIV;

        private ImageView typeIcon;

        private TextView name;

        private TextView desc;
    }
}
